package situ.autoweter.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import situ.autoweter.entity.PyUserhistory;
import situ.autoweter.entity.billList;
import situ.autoweter.entity.blist;
import situ.autoweter.service.PyBillService;
import situ.autoweter.entity.PyBill;
import java.util.*;
/**
 * PyBill的路由接口服务
 * 
 * @author 胡文
 *
 */
@Controller
public class PyBillController {

	/** PyBillService服务 */
	@Autowired
	private PyBillService pyBillService;
	
	/**
	 * 查询所有PyBill数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryPyBill", produces = {"application/json;charset=UTF-8"})
	public String find(PyBill value,Map map) {
		 List<PyBill> list= pyBillService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	/**
	 * 通过id查询PyBill数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "queryPyBillById/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") String id,Map map) {
        PyBill obj=  pyBillService.findOne(id);
        map.put("PyBill",obj);
        return "页面名称自己改";
	}
	
	/**
	 * 插入PyBill属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "savePyBill", produces = {"application/json;charset=UTF-8"})
	public String save(PyBill value) {
		  pyBillService.saveNotNull(value);
        return "redirect:/queryPyBill";
	}
	
	/**
	 * 更新PyBill属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePyBill", produces = {"application/json;charset=UTF-8"})
	public String update(PyBill value) {
		  pyBillService.updateNotNullById(value);
          return "redirect:/queryPyBill";
	}
	
	/**
	 * 通过id删除PyBill数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "delPyBillById/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") String id) {
		  pyBillService.deleteById(id);
          return "redirect:/queryPyBill";
	}

	@RequestMapping("pay_batch.html")
	public String query(Map map) {
		List<Map> list = pyBillService.query();
		Integer InvoiceNo=pyBillService.queryInvoiceNo();
		map.put("InvoiceNo", InvoiceNo);
        map.put("list", list);
		return "page/pay_batch";
	}
	@PostMapping("paybill")
	public String paybill(blist b){
		if(b.getBlist()!=null) {

			pyBillService.updatebill(b);
		}

        return "redirect:/pay_batch.html";
	}


}
